using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Resource.@string;
using MicroMsg.Scene.Image;
using MicroMsg.Storage;
using MicroMsg.UI.Page;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.UserContrl
{
	public class ChatSlideImgCtrl : UserControl
	{
		private const double screenW = 480.0;
		private const double screenH = 750.0;
		public ChatMsg mCuChatMsg;
		public string mCuImgStr;
		public int imageLen;
		public int hdImageLen;
		private double progress;
		private EventWatcher downLoadSuccessWatcher;
		private EventWatcher downLoadFailWatcher;
		private EventWatcher downLoadProgressWatcher;
		private bool isEnableDrag = true;
		private double initialAngle;
		private double initialScale;
		private double initialX;
		private double initialY;
		private double maxRadio = 5.0;
		private static Dictionary<int, int> progressDic = new Dictionary<int, int>();
		internal Canvas LayoutRoot;
		internal Border ImgView;
		internal Image ShowImg;
		internal CompositeTransform transform;
		internal GestureListener borderListener;
		internal Canvas LoadingView;
		internal Image DefaultImg;
		internal DownloadProgressBar DownLoadProgressBar;
		internal TextBlock InfoTxt;
		private bool _contentLoaded;
		public bool bDownloadFullImage
		{
			get
			{
				return !string.IsNullOrEmpty(ChatMsgMgr.getMsgImage(this.mCuChatMsg)) && ChatSlideImgCtrl.getIsDownloading(this.mCuChatMsg.nMsgLocalID);
			}
		}
		public bool bDownloading
		{
			get
			{
				return ChatSlideImgCtrl.getIsDownloading(this.mCuChatMsg.nMsgLocalID);
			}
		}
		public ChatSlideImgCtrl()
		{
			this.InitializeComponent();
			base.add_Unloaded(new RoutedEventHandler(this.ChatSlideImgCtrl_Unloaded));
			this.ImgDownLoadInit();
		}
		private void ChatSlideImgCtrl_Unloaded(object sender, RoutedEventArgs e)
		{
			this.ImgDownLoadUnit();
		}
		private void InitMsgData()
		{
			if (!ChatMsgMgr.getImageLenFromContent(this.mCuChatMsg, ref this.imageLen, ref this.hdImageLen))
			{
				Log.smethod_1(base.GetType().get_Name(), "get image len error, from xml parse");
			}
			this.imageLen /= 1000;
			this.hdImageLen /= 1000;
			if (this.imageLen == 0)
			{
				BitmapImage bitmapImage = ImageCacheMgr.loadImage(ChatMsgMgr.getMsgThumbnail(this.mCuChatMsg), ImageCacheType.MsgImg);
				if (bitmapImage != null)
				{
					this.imageLen = bitmapImage.GetHashCode() % 20 + 40;
					return;
				}
				this.imageLen = 50;
			}
		}
		public void InitView(ChatMsg mCuMsg)
		{
			if (mCuMsg == null)
			{
				return;
			}
			this.mCuChatMsg = mCuMsg;
			this.InitMsgData();
			string msgImage = ChatMsgMgr.getMsgImage(this.mCuChatMsg);
			if (!string.IsNullOrEmpty(msgImage) && !ChatSlideImgCtrl.getIsDownloading(this.mCuChatMsg.nMsgLocalID))
			{
				Log.smethod_5(base.GetType().get_Name(), "image already download:" + msgImage);
				this.ShowImgView(msgImage);
				return;
			}
			Log.smethod_5(base.GetType().get_Name(), "mCuMsg.nStatus = " + mCuMsg.nStatus);
			Log.smethod_5(base.GetType().get_Name(), "start download,local id:" + mCuMsg.nMsgLocalID);
			if (!ChatSlideImgCtrl.getIsDownloading(this.mCuChatMsg.nMsgLocalID) && ChatMsgMgr.downloadMsgImage(this.mCuChatMsg, 0) == 0)
			{
				this.ShowFailView();
			}
			this.progress = (double)ChatSlideImgCtrl.getProgressOfId(this.mCuChatMsg.nMsgLocalID);
			this.ShowLoadingView();
			this.ShowProgress();
		}
		public void ClearView()
		{
			this.LayoutRoot.set_Visibility(1);
		}
		public void ShowFailView()
		{
			this.LayoutRoot.set_Visibility(0);
			this.isEnableDrag = false;
			this.LoadingView.set_Visibility(0);
			this.ImgView.set_Visibility(1);
			this.InfoTxt.set_Text(strings.ImageViewDownError);
		}
		public void ShowImgView(string imgUrl)
		{
			this.LayoutRoot.set_Visibility(0);
			this.LayoutRoot.set_Background(new SolidColorBrush(Colors.get_Black()));
			if (string.IsNullOrEmpty(imgUrl))
			{
				this.ShowFailView();
				return;
			}
			this.mCuImgStr = imgUrl;
			BitmapImage bitmapImage = ImageCacheMgr.loadFromFile(imgUrl);
			if (bitmapImage == null)
			{
				this.InfoTxt.set_Text(strings.ImageViewLoadError);
				this.LoadingView.set_Visibility(0);
				this.ImgView.set_Visibility(1);
			}
			else
			{
				this.ShowImg.set_Source(bitmapImage);
				this.LoadingView.set_Visibility(1);
				this.ImgView.set_Visibility(0);
				if (bitmapImage != null)
				{
					double num = Math.Max(480.0 / (double)bitmapImage.get_PixelWidth(), (double)bitmapImage.get_PixelWidth() / 480.0);
					double num2 = Math.Max(800.0 / (double)bitmapImage.get_PixelHeight(), (double)bitmapImage.get_PixelHeight() / 800.0);
					this.maxRadio = Math.Max(Math.Max(num, num2), 5.0);
				}
				else
				{
					this.maxRadio = 5.0;
				}
			}
			BasePage rootPage = ToolFunction.GetRootPage();
			if (rootPage is ChatSlideImgPage)
			{
				ChatSlideImgPage chatSlideImgPage = rootPage as ChatSlideImgPage;
				chatSlideImgPage.EnableSaveIcon();
			}
		}
		public void ShowLoadingView()
		{
			this.LayoutRoot.set_Visibility(0);
			this.LayoutRoot.set_Background(R.theme.IMGVIEW_BK_BRUSH);
			this.LoadingView.set_Visibility(0);
			this.ImgView.set_Visibility(1);
			ChatSlideImgCtrl.UpdateToDic(this.mCuChatMsg.nMsgLocalID, (int)this.progress);
			BasePage rootPage = ToolFunction.GetRootPage();
			if (rootPage is ChatSlideImgPage)
			{
				ChatSlideImgPage chatSlideImgPage = rootPage as ChatSlideImgPage;
				chatSlideImgPage.DisAbleSaveIcon();
			}
		}
		public void DownLoadFullImgView()
		{
			this.progress = 0.0;
			this.ShowLoadingView();
			this.ShowProgress();
			if (ChatMsgMgr.downloadMsgImage(this.mCuChatMsg, 1) == 0)
			{
				this.ShowFailView();
			}
		}
		private void ShowProgress()
		{
			int num;
			if (!this.bDownloadFullImage)
			{
				num = this.imageLen;
			}
			else
			{
				num = this.hdImageLen;
			}
			if (num <= 3)
			{
				num = 4;
			}
			int num2 = (int)this.progress;
			if (num2 >= num - 3)
			{
				num2 = num - 3;
			}
			double num3 = (double)num2 / (double)num * 100.0;
			if (num3 > 97.0)
			{
				num3 = 97.0;
			}
			if (num3 < 0.0)
			{
				num3 = 0.0;
			}
			this.DownLoadProgressBar.set_Value(num3);
			this.InfoTxt.set_Text(string.Format(strings.ImageViewDownInfo, num2, num));
		}
		private void ImgDownLoadInit()
		{
			if (this.downLoadSuccessWatcher == null)
			{
				this.downLoadSuccessWatcher = new EventWatcher(this, null, new EventHandlerDelegate(this.on_LoadSuccess_EventHandler));
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_DOWNLOADIMG_COMPLETE, this.downLoadSuccessWatcher);
			}
			if (this.downLoadFailWatcher == null)
			{
				this.downLoadFailWatcher = new EventWatcher(this, null, new EventHandlerDelegate(this.on_LoadFail_EventHandler));
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_DOWNLOADIMG_FAIL, this.downLoadFailWatcher);
			}
			if (this.downLoadProgressWatcher == null)
			{
				this.downLoadProgressWatcher = new EventWatcher(this, null, new EventHandlerDelegate(this.on_LoadProgress_EventHandler));
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_DOWNLOADIMG_PROGRESS, this.downLoadProgressWatcher);
			}
		}
		private void ImgDownLoadUnit()
		{
			if (this.downLoadSuccessWatcher != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_DOWNLOADIMG_COMPLETE, this.downLoadSuccessWatcher);
				this.downLoadSuccessWatcher = null;
			}
			if (this.downLoadFailWatcher != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_DOWNLOADIMG_FAIL, this.downLoadFailWatcher);
				this.downLoadFailWatcher = null;
			}
			if (this.downLoadProgressWatcher != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_DOWNLOADIMG_PROGRESS, this.downLoadProgressWatcher);
				this.downLoadProgressWatcher = null;
			}
		}
		private void on_LoadProgress_EventHandler(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (this.mCuChatMsg == null)
			{
				return;
			}
			Log.smethod_4(base.GetType().get_Name(), "on_LoadProgress_EventHandler");
			if (evtArgs == null)
			{
				return;
			}
			if (evtArgs.mEventID == EventConst.ON_NETSCENE_DOWNLOADIMG_PROGRESS)
			{
				ParamImgDownProgress paramImgDownProgress = evtArgs.mObject as ParamImgDownProgress;
				if (paramImgDownProgress == null)
				{
					Log.smethod_1(base.GetType().get_Name(), "ON_NETSCENE_DOWNLOADIMG_PROGRESS AND ParamReturn is null");
					return;
				}
				if (paramImgDownProgress.mImageLocalId == this.mCuChatMsg.nMsgLocalID)
				{
					this.progress = double.Parse(paramImgDownProgress.mstrProgress);
					this.ShowProgress();
				}
				ChatSlideImgCtrl.UpdateToDic(paramImgDownProgress.mImageLocalId, (int)double.Parse(paramImgDownProgress.mstrProgress));
			}
		}
		private void on_LoadSuccess_EventHandler(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			Log.smethod_5(base.GetType().get_Name(), "on_LoadSuccess_EventHandler");
			if (evtArgs == null)
			{
				Log.smethod_1(base.GetType().get_Name(), "on_LoadSuccess_EventHandler AND evtArgs == null");
				return;
			}
			if (evtArgs.mObject == null)
			{
				Log.smethod_1(base.GetType().get_Name(), "on_LoadSuccess_EventHandler AND evtArgs.mObject == null");
				return;
			}
			if (this.mCuChatMsg == null)
			{
				return;
			}
			if (evtArgs.mEventID == EventConst.ON_NETSCENE_DOWNLOADIMG_COMPLETE)
			{
				ParamReturn paramReturn = evtArgs.mObject as ParamReturn;
				if (paramReturn == null)
				{
					Log.smethod_1(base.GetType().get_Name(), "ON_NETSCENE_DOWNLOADIMG_COMPLETE AND ParamReturn is null");
					return;
				}
				if (this.mCuChatMsg == null)
				{
					return;
				}
				if (paramReturn.mImageLocalId == this.mCuChatMsg.nMsgLocalID)
				{
					string mStrImgPath = paramReturn.mStrImgPath;
					if (string.IsNullOrEmpty(mStrImgPath))
					{
						this.ShowFailView();
					}
					else
					{
						this.ShowImgView(mStrImgPath);
						this.mCuChatMsg = StorageMgr.chatMsg.getMsg(this.mCuChatMsg.nMsgLocalID);
						this.InitMsgData();
					}
				}
				ChatSlideImgCtrl.RemoveFromDic(paramReturn.mImageLocalId);
			}
		}
		private void on_LoadFail_EventHandler(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			Log.smethod_5(base.GetType().get_Name(), "on_LoadFail_EventHandler");
			if (evtArgs.mEventID == EventConst.ON_NETSCENE_DOWNLOADIMG_FAIL)
			{
				ParamReturn paramReturn = evtArgs.mObject as ParamReturn;
				if (paramReturn == null)
				{
					Log.smethod_1(base.GetType().get_Name(), "ON_NETSCENE_DOWNLOADIMG_Fail AND ParamReturn is null");
					return;
				}
				if (this.mCuChatMsg == null)
				{
					return;
				}
				if (paramReturn.mImageLocalId == this.mCuChatMsg.nMsgLocalID)
				{
					this.ShowFailView();
				}
				ChatSlideImgCtrl.RemoveFromDic(paramReturn.mImageLocalId);
			}
		}
		private void OnPinchStarted(object sender, PinchStartedGestureEventArgs e)
		{
			if (!this.isEnableDrag)
			{
				return;
			}
			this.initialScale = this.transform.get_ScaleX();
		}
		private CompositeTransform GetCopyTransform(CompositeTransform trans)
		{
			CompositeTransform compositeTransform = new CompositeTransform();
			compositeTransform.set_CenterX(trans.get_CenterX());
			compositeTransform.set_CenterY(trans.get_CenterY());
			compositeTransform.set_ScaleX(trans.get_ScaleX());
			compositeTransform.set_ScaleY(trans.get_ScaleY());
			compositeTransform.set_TranslateX(trans.get_TranslateX());
			compositeTransform.set_TranslateY(trans.get_TranslateY());
			return compositeTransform;
		}
		private CompositeTransform GetContraryTransform(CompositeTransform trans)
		{
			CompositeTransform compositeTransform = new CompositeTransform();
			compositeTransform.set_CenterX(0.0);
			compositeTransform.set_CenterY(0.0);
			compositeTransform.set_ScaleX(1.0 / trans.get_ScaleX());
			compositeTransform.set_ScaleY(1.0 / trans.get_ScaleY());
			compositeTransform.set_TranslateX(0.0 - trans.get_TranslateX());
			compositeTransform.set_TranslateY(0.0 - trans.get_TranslateY());
			return compositeTransform;
		}
		private void OnPinchDelta(object sender, PinchGestureEventArgs e)
		{
			if (!this.isEnableDrag)
			{
				return;
			}
			double num = e.DistanceRatio;
			if (num > 2.0)
			{
				num = 2.0;
			}
			else
			{
				if (num < 0.3)
				{
					num = 0.3;
				}
			}
			if (this.initialScale * num > 0.65 && this.initialScale * num < this.maxRadio)
			{
				Point resultPoint = new Point(e.GetPosition(this.ImgView).get_X(), e.GetPosition(this.ImgView).get_Y());
				Point pointSrc = default(Point);
				bool oldPoint = this.GetOldPoint(resultPoint, this.transform, ref pointSrc);
				CompositeTransform copyTransform = this.GetCopyTransform(this.transform);
				copyTransform.set_ScaleX(this.initialScale * num);
				copyTransform.set_ScaleY(this.initialScale * num);
				Point point = default(Point);
				bool oldPoint2 = this.GetOldPoint(resultPoint, copyTransform, ref point);
				Point point2 = default(Point);
				bool transformPoint = this.GetTransformPoint(pointSrc, copyTransform, ref point2);
				this.transform.set_ScaleX(this.initialScale * num);
				this.transform.set_ScaleY(this.initialScale * num);
				if (oldPoint && oldPoint2 && transformPoint)
				{
					CompositeTransform expr_148 = this.transform;
					expr_148.set_TranslateX(expr_148.get_TranslateX() + (resultPoint.get_X() - point2.get_X()));
					CompositeTransform expr_169 = this.transform;
					expr_169.set_TranslateY(expr_169.get_TranslateY() + (resultPoint.get_Y() - point2.get_Y()));
				}
				return;
			}
		}
		private void GestureListener_DragStarted(object sender, DragStartedGestureEventArgs e)
		{
			if (!this.isEnableDrag)
			{
				return;
			}
			this.initialX = this.transform.get_TranslateX();
			this.initialY = this.transform.get_TranslateY();
		}
		private void GestureListener_DragDelta(object sender, DragDeltaGestureEventArgs e)
		{
			if (!this.isEnableDrag)
			{
				return;
			}
			if (this.transform.get_ScaleX() == 1.0)
			{
				return;
			}
			CompositeTransform expr_26 = this.transform;
			expr_26.set_TranslateX(expr_26.get_TranslateX() + e.HorizontalChange * 1.2);
			CompositeTransform expr_48 = this.transform;
			expr_48.set_TranslateY(expr_48.get_TranslateY() + e.VerticalChange * 1.2);
		}
		private void GestureListener_DragCompleted(object sender, DragCompletedGestureEventArgs e)
		{
			if (!this.isEnableDrag)
			{
				return;
			}
			this.AdjustImagePosition();
		}
		private void AdjustImagePosition()
		{
			double num = 0.0;
			double num2 = 0.0;
			if (!this.IsShouldReplace(ref num, ref num2))
			{
				return;
			}
			TimeSpan timeSpan = TimeSpan.FromSeconds(0.3);
			Storyboard storyboard = new Storyboard();
			double num3 = this.transform.get_TranslateX();
			double num4 = this.transform.get_TranslateX() + num;
			DoubleAnimation doubleAnimation = new DoubleAnimation();
			doubleAnimation.set_From(new double?(num3));
			doubleAnimation.set_To(new double?(num4));
			doubleAnimation.set_Duration(timeSpan);
			DoubleAnimation doubleAnimation2 = doubleAnimation;
			Storyboard.SetTarget(doubleAnimation2, this.transform);
			Storyboard.SetTargetProperty(doubleAnimation2, new PropertyPath(CompositeTransform.TranslateXProperty));
			storyboard.get_Children().Add(doubleAnimation2);
			num3 = this.transform.get_TranslateY();
			num4 = this.transform.get_TranslateY() + num2;
			DoubleAnimation doubleAnimation3 = new DoubleAnimation();
			doubleAnimation3.set_From(new double?(num3));
			doubleAnimation3.set_To(new double?(num4));
			doubleAnimation3.set_Duration(timeSpan);
			DoubleAnimation doubleAnimation4 = doubleAnimation3;
			Storyboard.SetTarget(doubleAnimation4, this.transform);
			Storyboard.SetTargetProperty(doubleAnimation4, new PropertyPath(CompositeTransform.TranslateYProperty));
			storyboard.get_Children().Add(doubleAnimation4);
			storyboard.Begin();
		}
		private void ResumeStoryBoard()
		{
			TimeSpan timeSpan = TimeSpan.FromSeconds(0.3);
			Storyboard storyboard = new Storyboard();
			double num = this.transform.get_ScaleX();
			double num2 = 1.0;
			DoubleAnimation doubleAnimation = new DoubleAnimation();
			doubleAnimation.set_From(new double?(num));
			doubleAnimation.set_To(new double?(num2));
			doubleAnimation.set_Duration(timeSpan);
			DoubleAnimation doubleAnimation2 = doubleAnimation;
			Storyboard.SetTarget(doubleAnimation2, this.transform);
			Storyboard.SetTargetProperty(doubleAnimation2, new PropertyPath(CompositeTransform.ScaleXProperty));
			storyboard.get_Children().Add(doubleAnimation2);
			num = this.transform.get_ScaleY();
			num2 = 1.0;
			DoubleAnimation doubleAnimation3 = new DoubleAnimation();
			doubleAnimation3.set_From(new double?(num));
			doubleAnimation3.set_To(new double?(num2));
			doubleAnimation3.set_Duration(timeSpan);
			DoubleAnimation doubleAnimation4 = doubleAnimation3;
			Storyboard.SetTarget(doubleAnimation4, this.transform);
			Storyboard.SetTargetProperty(doubleAnimation4, new PropertyPath(CompositeTransform.ScaleYProperty));
			storyboard.get_Children().Add(doubleAnimation4);
			num = this.transform.get_TranslateX();
			num2 = 0.0;
			DoubleAnimation doubleAnimation5 = new DoubleAnimation();
			doubleAnimation5.set_From(new double?(num));
			doubleAnimation5.set_To(new double?(num2));
			doubleAnimation5.set_Duration(timeSpan);
			DoubleAnimation doubleAnimation6 = doubleAnimation5;
			Storyboard.SetTarget(doubleAnimation6, this.transform);
			Storyboard.SetTargetProperty(doubleAnimation6, new PropertyPath(CompositeTransform.TranslateXProperty));
			storyboard.get_Children().Add(doubleAnimation6);
			num = this.transform.get_TranslateY();
			num2 = 0.0;
			DoubleAnimation doubleAnimation7 = new DoubleAnimation();
			doubleAnimation7.set_From(new double?(num));
			doubleAnimation7.set_To(new double?(num2));
			doubleAnimation7.set_Duration(timeSpan);
			DoubleAnimation doubleAnimation8 = doubleAnimation7;
			Storyboard.SetTarget(doubleAnimation8, this.transform);
			Storyboard.SetTargetProperty(doubleAnimation8, new PropertyPath(CompositeTransform.TranslateYProperty));
			storyboard.get_Children().Add(doubleAnimation8);
			num = this.transform.get_CenterX();
			num2 = 0.0;
			DoubleAnimation doubleAnimation9 = new DoubleAnimation();
			doubleAnimation9.set_From(new double?(num));
			doubleAnimation9.set_To(new double?(num2));
			doubleAnimation9.set_Duration(timeSpan);
			DoubleAnimation doubleAnimation10 = doubleAnimation9;
			Storyboard.SetTarget(doubleAnimation10, this.transform);
			Storyboard.SetTargetProperty(doubleAnimation10, new PropertyPath(CompositeTransform.CenterXProperty));
			storyboard.get_Children().Add(doubleAnimation10);
			num = this.transform.get_CenterY();
			num2 = 0.0;
			DoubleAnimation doubleAnimation11 = new DoubleAnimation();
			doubleAnimation11.set_From(new double?(num));
			doubleAnimation11.set_To(new double?(num2));
			doubleAnimation11.set_Duration(timeSpan);
			DoubleAnimation doubleAnimation12 = doubleAnimation11;
			Storyboard.SetTarget(doubleAnimation12, this.transform);
			Storyboard.SetTargetProperty(doubleAnimation12, new PropertyPath(CompositeTransform.CenterYProperty));
			storyboard.get_Children().Add(doubleAnimation12);
			storyboard.Begin();
		}
		private Rect GetOriginRect(ref double xRadio, ref double yRadio)
		{
			Rect result = default(Rect);
			BitmapImage bitmapImage = this.ShowImg.get_Source() as BitmapImage;
			if (bitmapImage == null)
			{
				return result;
			}
			double num;
			double num2;
			double num5;
			double num6;
			if ((double)(bitmapImage.get_PixelHeight() / bitmapImage.get_PixelWidth()) > 1.5625)
			{
				num = 0.0;
				num2 = 750.0;
				double num3 = 750.0 / (double)bitmapImage.get_PixelHeight();
				double num4 = (double)bitmapImage.get_PixelWidth() * num3;
				num5 = (480.0 - num4) / 2.0;
				num6 = num5 + num4;
			}
			else
			{
				num5 = 0.0;
				num6 = 480.0;
				double num7 = 480.0 / (double)bitmapImage.get_PixelWidth();
				double num8 = (double)bitmapImage.get_PixelHeight() * num7;
				num = (750.0 - num8) / 2.0;
				num2 = 750.0 - num;
			}
			xRadio = (num6 - num5) / 480.0;
			yRadio = (num2 - num) / 750.0;
			result = new Rect(num5, num, num6 - num5, num2 - num);
			return result;
		}
		private bool IsShouldReplace(ref double detaX, ref double detaY)
		{
			Rect transformRect = this.GetTransformRect(this.transform);
			double num = 0.0;
			double num2 = 0.0;
			this.GetOriginRect(ref num, ref num2);
			if (transformRect.get_IsEmpty())
			{
				return false;
			}
			double num3;
			double num4;
			if (transformRect.get_Width() < 480.0)
			{
				num3 = (480.0 - transformRect.get_Width()) / 2.0;
				num4 = num3 + transformRect.get_Width();
			}
			else
			{
				num3 = 0.0;
				num4 = 480.0;
			}
			bool result = false;
			if (transformRect.get_Width() < 480.0)
			{
				if (transformRect.get_Left() < num3)
				{
					detaX = num3 - transformRect.get_Left();
					result = true;
				}
				else
				{
					if (transformRect.get_Right() > num4)
					{
						detaX = num4 - transformRect.get_Right();
						result = true;
					}
				}
			}
			else
			{
				if (transformRect.get_Left() > 0.0 && transformRect.get_Right() > 480.0)
				{
					detaX = 0.0 - transformRect.get_Left();
					if (detaX < 0.0)
					{
						result = true;
					}
					else
					{
						detaX = 0.0;
					}
				}
				else
				{
					if (transformRect.get_Left() < 0.0 && transformRect.get_Right() < 480.0)
					{
						detaX = 480.0 - transformRect.get_Right();
						if (detaX > 0.0)
						{
							result = true;
						}
						else
						{
							detaX = 0.0;
						}
					}
				}
			}
			double num5;
			double num6;
			if (transformRect.get_Height() < 750.0)
			{
				num5 = (750.0 - transformRect.get_Height()) / 2.0;
				num6 = num5 + transformRect.get_Height();
			}
			else
			{
				num5 = 0.0;
				num6 = 750.0;
			}
			if (transformRect.get_Height() < 750.0)
			{
				if (transformRect.get_Top() > num5)
				{
					detaY = num5 - transformRect.get_Top();
					result = true;
				}
				else
				{
					if (transformRect.get_Bottom() < num6)
					{
						detaY = num6 - transformRect.get_Bottom();
						result = true;
					}
				}
			}
			else
			{
				if (transformRect.get_Top() > 0.0 && transformRect.get_Bottom() > 750.0)
				{
					detaY = num5 - transformRect.get_Top();
					if (detaY < 0.0)
					{
						result = true;
					}
					else
					{
						detaY = 0.0;
					}
				}
				else
				{
					if (transformRect.get_Top() < 0.0 && transformRect.get_Bottom() < 750.0)
					{
						detaY = num6 - transformRect.get_Bottom();
						if (detaY >= 0.0)
						{
							result = true;
						}
						else
						{
							detaY = 0.0;
						}
					}
				}
			}
			return result;
		}
		private bool GetTransformPoint(Point pointSrc, CompositeTransform trans, ref Point resultPoint)
		{
			double num = 0.0;
			double num2 = 0.0;
			Rect originRect = this.GetOriginRect(ref num, ref num2);
			if (originRect.get_IsEmpty())
			{
				return false;
			}
			if (pointSrc.get_X() < originRect.get_Left() || pointSrc.get_X() > originRect.get_Right())
			{
				return false;
			}
			if (pointSrc.get_Y() >= originRect.get_Top() && pointSrc.get_Y() <= originRect.get_Bottom())
			{
				double num3 = (pointSrc.get_X() - originRect.get_Left()) / originRect.get_Width();
				double num4 = (pointSrc.get_Y() - originRect.get_Top()) / originRect.get_Height();
				Rect transformRect = this.GetTransformRect(trans);
				resultPoint = new Point(transformRect.get_Left() + transformRect.get_Width() * num3, transformRect.get_Top() + transformRect.get_Height() * num4);
				return true;
			}
			return false;
		}
		private bool GetOldPoint(Point resultPoint, CompositeTransform trans, ref Point pointSrc)
		{
			double num = 0.0;
			double num2 = 0.0;
			Rect originRect = this.GetOriginRect(ref num, ref num2);
			if (originRect.get_IsEmpty())
			{
				return false;
			}
			Rect transformRect = this.GetTransformRect(trans);
			if (resultPoint.get_X() < transformRect.get_Left() || resultPoint.get_X() > transformRect.get_Right())
			{
				return false;
			}
			if (resultPoint.get_Y() >= transformRect.get_Top() && resultPoint.get_Y() <= transformRect.get_Bottom())
			{
				double num3 = (resultPoint.get_X() - transformRect.get_Left()) / transformRect.get_Width();
				double num4 = (resultPoint.get_Y() - transformRect.get_Top()) / transformRect.get_Height();
				pointSrc = new Point(originRect.get_Left() + originRect.get_Width() * num3, originRect.get_Top() + originRect.get_Height() * num4);
				return true;
			}
			return false;
		}
		private Rect GetTransformRect(CompositeTransform trans)
		{
			double num = 0.0;
			double num2 = 0.0;
			Rect originRect = this.GetOriginRect(ref num, ref num2);
			if (originRect.get_IsEmpty())
			{
				return originRect;
			}
			Rect rect = new Rect(0.0, 0.0, originRect.get_Width(), originRect.get_Height());
			Rect rect2 = trans.TransformBounds(rect);
			Rect result = new Rect(originRect.get_Left() + rect2.get_Left(), originRect.get_Top() + rect2.get_Top(), rect2.get_Width(), rect2.get_Height());
			return result;
		}
		private void GestureListener_PinchCompleted(object sender, PinchGestureEventArgs e)
		{
			if (this.transform.get_ScaleX() < 1.0)
			{
				this.ResumeStoryBoard();
				return;
			}
			this.AdjustImagePosition();
		}
		public static void UpdateToDic(int mLocalId, int mProgress)
		{
			if (ChatSlideImgCtrl.progressDic == null)
			{
				ChatSlideImgCtrl.progressDic = new Dictionary<int, int>();
			}
			if (ChatSlideImgCtrl.progressDic.ContainsKey(mLocalId))
			{
				ChatSlideImgCtrl.progressDic.set_Item(mLocalId, mProgress);
				return;
			}
			ChatSlideImgCtrl.progressDic.Add(mLocalId, mProgress);
		}
		public static void RemoveFromDic(int mLocalId)
		{
			if (ChatSlideImgCtrl.progressDic == null)
			{
				return;
			}
			if (ChatSlideImgCtrl.progressDic.ContainsKey(mLocalId))
			{
				ChatSlideImgCtrl.progressDic.Remove(mLocalId);
			}
		}
		public static int getProgressOfId(int mLocalId)
		{
			if (ChatSlideImgCtrl.progressDic != null && ChatSlideImgCtrl.progressDic.ContainsKey(mLocalId))
			{
				return ChatSlideImgCtrl.progressDic.get_Item(mLocalId);
			}
			return 0;
		}
		public static bool getIsDownloading(int mLocalId)
		{
			return ChatSlideImgCtrl.progressDic != null && ChatSlideImgCtrl.progressDic.ContainsKey(mLocalId);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Chat/SlideImageView/ChatSlideImgCtrl.xaml", 2));
			this.LayoutRoot = (Canvas)base.FindName("LayoutRoot");
			this.ImgView = (Border)base.FindName("ImgView");
			this.ShowImg = (Image)base.FindName("ShowImg");
			this.transform = (CompositeTransform)base.FindName("transform");
			this.borderListener = (GestureListener)base.FindName("borderListener");
			this.LoadingView = (Canvas)base.FindName("LoadingView");
			this.DefaultImg = (Image)base.FindName("DefaultImg");
			this.DownLoadProgressBar = (DownloadProgressBar)base.FindName("DownLoadProgressBar");
			this.InfoTxt = (TextBlock)base.FindName("InfoTxt");
		}
	}
}
